package com.cdut.logistics.service.impl.system;

import com.cdut.logistics.model.dao.datacentre.Dict;
import com.cdut.logistics.model.dao.system.authorityDAO;
import com.cdut.logistics.model.entity.system.Authority;
import com.cdut.logistics.service.interf.system.AuthorityService;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName: AuthorityServiceImp  
 * @Description: TODO(权限类接口的实现类)  
 * @author lxh
 * @date 2018年1月28日 下午4:21:14
 */
public class AuthorityServiceImp implements AuthorityService {

	authorityDAO dao=new authorityDAO();
	public boolean addAuthority( String name, String url,
			String is_use, String active,Date created) {
		boolean result=dao.addAuthority(name, url, is_use, active,created);
		return result;
	}

	public boolean deleteAuthority(String id) {
		boolean result=dao.deleteAuthority(id);
		return result;
	}

	public boolean updateAuthority(String id, String name, String url,Date updated) {
		boolean result=dao.updateAuthority(id, name, url,updated);
		return result;
	}

	public Authority queryAuthorityById(String id) {
		Authority result=dao.queryAuthorityById(id);
		return result;
	}


	@Override
	public List<Authority> queryAllAuthority() {
		// TODO Auto-generated method stub	
		List<Authority> authorityList=dao.queryAllAuthority();
		return authorityList;
	}

	@Override
	public Map<String, Integer> queryIfAuthority(int authority_id) {
		Dict dict = new Dict();
		List<Dict> authorityList=dict.find(dict.sql5,"authority");
		String url=dao.queryUrlById(authority_id);
		String[] url_arr = new String[1];
		try {
			url_arr = url.split("\\*");
		} catch (Exception e) {
			url_arr[0] = url;
		}
		Map<String, Integer> m = new HashMap<String, Integer>();
		for(Dict d:authorityList){
			m.put(d.getdescription(), 0);
			for(String s:url_arr){
				if(d.getStr("description").equals(s))
					m.put(d.getdescription(), 1);
			}
		}
		return m;
	}


}
